<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- This is a non-exposed internal module.</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- This code contains utility function and data structures that are used</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- to improve the efficiency of several instances in the Data.* namespace.</span><span>
</span><span id="line-9"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-10"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Functor.Utils</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Coerce.html"><span class="hs-identifier">Data.Coerce</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Coercible"><span class="hs-identifier">Coercible</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#coerce"><span class="hs-identifier">coerce</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Base.html#Applicative"><span class="hs-identifier">Applicative</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#Functor"><span class="hs-identifier">Functor</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier">Maybe</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#Monoid"><span class="hs-identifier">Monoid</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier">Ord</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-14"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#Semigroup"><span class="hs-identifier">Semigroup</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#%24"><span class="hs-operator">($)</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#otherwise"><span class="hs-identifier">otherwise</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span>
</span><span id="line-16"></span><span class="hs-comment">-- We don't expose Max and Min because, as Edward Kmett pointed out to me,</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- there are two reasonable ways to define them. One way is to use Maybe, as we</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- do here; the other way is to impose a Bounded constraint on the Monoid</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- instance. We may eventually want to add both versions, but we don't want to</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- trample on anyone's toes by imposing Max = MaxMaybe.</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-keyword">newtype</span><span> </span><span id="Max"><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-var">Max</span></a></span></span><span> </span><span id="local-6989586621679514579"><span class="annot"><a href="#local-6989586621679514579"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Max"><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-var">Max</span></a></span></span><span> </span><span class="hs-special">{</span><span id="getMax"><span class="annot"><span class="annottext">forall a. Max a -&gt; Maybe a
</span><a href="Data.Functor.Utils.html#getMax"><span class="hs-identifier hs-var hs-var">getMax</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514579"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-23"></span><span class="hs-keyword">newtype</span><span> </span><span id="Min"><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-var">Min</span></a></span></span><span> </span><span id="local-6989586621679514577"><span class="annot"><a href="#local-6989586621679514577"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Min"><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-var">Min</span></a></span></span><span> </span><span class="hs-special">{</span><span id="getMin"><span class="annot"><span class="annottext">forall a. Min a -&gt; Maybe a
</span><a href="Data.Functor.Utils.html#getMin"><span class="hs-identifier hs-var hs-var">getMin</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514577"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span class="hs-comment">-- | @since 4.11.0.0</span><span>
</span><span id="line-26"></span><span id="local-6989586621679514572"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514472"><span id="local-6989586621679514474"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-type">Ord</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514572"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#Semigroup"><span class="hs-identifier hs-type">Semigroup</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514572"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-28"></span><span>    </span><span id="local-6989586621679514469"><span class="annot"><span class="annottext">Max a
</span><a href="#local-6989586621679514469"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679514468"><span class="annot"><span class="annottext">&lt;&gt; :: Max a -&gt; Max a -&gt; Max a
</span><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Max a
</span><a href="#local-6989586621679514469"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-29"></span><span>    </span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span id="local-6989586621679514467"><span class="annot"><span class="annottext">Max a
</span><a href="#local-6989586621679514467"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Max a
</span><a href="#local-6989586621679514467"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span id="local-6989586621679514466"><span class="annot"><span class="annottext">m :: Maybe a
</span><a href="#local-6989586621679514466"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679514465"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514465"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span id="local-6989586621679514464"><span class="annot"><span class="annottext">n :: Maybe a
</span><a href="#local-6989586621679514464"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679514463"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514463"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514465"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514463"><span class="hs-identifier hs-var">y</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Max a
forall a. Maybe a -&gt; Max a
</span><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-var">Max</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679514466"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-32"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Max a
forall a. Maybe a -&gt; Max a
</span><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-var">Max</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679514464"><span class="hs-identifier hs-var">n</span></a></span></span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-comment">-- | @since 4.8.0.0</span><span>
</span><span id="line-35"></span><span id="local-6989586621679514569"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514456"><span id="local-6989586621679514458"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-type">Ord</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514569"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#Monoid"><span class="hs-identifier hs-type">Monoid</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-type">Max</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514569"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-36"></span><span>    </span><span id="local-6989586621679514454"><span class="annot"><span class="annottext">mempty :: Max a
</span><a href="GHC.Base.html#mempty"><span class="hs-identifier hs-var hs-var hs-var hs-var">mempty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Max a
forall a. Maybe a -&gt; Max a
</span><a href="Data.Functor.Utils.html#Max"><span class="hs-identifier hs-var">Max</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span></span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span class="hs-comment">-- | @since 4.11.0.0</span><span>
</span><span id="line-39"></span><span id="local-6989586621679514567"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514449"><span id="local-6989586621679514451"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-type">Ord</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514567"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#Semigroup"><span class="hs-identifier hs-type">Semigroup</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514567"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-40"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-41"></span><span>    </span><span id="local-6989586621679514447"><span class="annot"><span class="annottext">Min a
</span><a href="#local-6989586621679514447"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679514446"><span class="annot"><span class="annottext">&lt;&gt; :: Min a -&gt; Min a -&gt; Min a
</span><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Min a
</span><a href="#local-6989586621679514447"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-42"></span><span>    </span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span id="local-6989586621679514445"><span class="annot"><span class="annottext">Min a
</span><a href="#local-6989586621679514445"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Min a
</span><a href="#local-6989586621679514445"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-43"></span><span>    </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span id="local-6989586621679514444"><span class="annot"><span class="annottext">m :: Maybe a
</span><a href="#local-6989586621679514444"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679514443"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514443"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span id="local-6989586621679514442"><span class="annot"><span class="annottext">n :: Maybe a
</span><a href="#local-6989586621679514442"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679514441"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514441"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514443"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514441"><span class="hs-identifier hs-var">y</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Min a
forall a. Maybe a -&gt; Min a
</span><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-var">Min</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679514444"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-45"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Min a
forall a. Maybe a -&gt; Min a
</span><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-var">Min</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679514442"><span class="hs-identifier hs-var">n</span></a></span></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-comment">-- | @since 4.8.0.0</span><span>
</span><span id="line-48"></span><span id="local-6989586621679514566"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514433"><span id="local-6989586621679514435"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-type">Ord</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514566"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#Monoid"><span class="hs-identifier hs-type">Monoid</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-type">Min</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514566"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-49"></span><span>    </span><span id="local-6989586621679514432"><span class="annot"><span class="annottext">mempty :: Min a
</span><a href="GHC.Base.html#mempty"><span class="hs-identifier hs-var hs-var hs-var hs-var">mempty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; Min a
forall a. Maybe a -&gt; Min a
</span><a href="Data.Functor.Utils.html#Min"><span class="hs-identifier hs-var">Min</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span></span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-comment">-- left-to-right state-transforming monad</span><span>
</span><span id="line-52"></span><span class="hs-keyword">newtype</span><span> </span><span id="StateL"><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span></span><span> </span><span id="local-6989586621679514565"><span class="annot"><a href="#local-6989586621679514565"><span class="hs-identifier hs-type">s</span></a></span></span><span> </span><span id="local-6989586621679514564"><span class="annot"><a href="#local-6989586621679514564"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="StateL"><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="runStateL"><span class="annot"><span class="annottext">forall s a. StateL s a -&gt; s -&gt; (s, a)
</span><a href="Data.Functor.Utils.html#runStateL"><span class="hs-identifier hs-var hs-var">runStateL</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679514565"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679514565"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679514564"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span class="hs-comment">-- | @since 4.0</span><span>
</span><span id="line-55"></span><span id="local-6989586621679514556"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514427"><span class="annot"><a href="GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514556"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-56"></span><span>    </span><span id="local-6989586621679514425"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; StateL s a -&gt; StateL s b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span id="local-6989586621679514424"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514424"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span id="local-6989586621679514423"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514423"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, b)) -&gt; StateL s b
forall s a. (s -&gt; (s, a)) -&gt; StateL s a
</span><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, b)) -&gt; StateL s b) -&gt; (s -&gt; (s, b)) -&gt; StateL s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514422"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514422"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514421"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514421"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514420"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514420"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514423"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514422"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514421"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514424"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514420"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span class="hs-comment">-- | @since 4.0</span><span>
</span><span id="line-59"></span><span id="local-6989586621679514539"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514411"><span id="local-6989586621679514413"><span class="annot"><a href="GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514539"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-60"></span><span>    </span><span id="local-6989586621679514409"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; StateL s a
</span><a href="GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679514408"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514408"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, a)) -&gt; StateL s a
forall s a. (s -&gt; (s, a)) -&gt; StateL s a
</span><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514407"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514407"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514407"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514408"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span>    </span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span id="local-6989586621679514406"><span class="annot"><span class="annottext">s -&gt; (s, a -&gt; b)
</span><a href="#local-6989586621679514406"><span class="hs-identifier hs-var">kf</span></a></span></span><span> </span><span id="local-6989586621679514405"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. StateL s (a -&gt; b) -&gt; StateL s a -&gt; StateL s b
</span><a href="GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;*&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span id="local-6989586621679514404"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514404"><span class="hs-identifier hs-var">kv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, b)) -&gt; StateL s b
forall s a. (s -&gt; (s, a)) -&gt; StateL s a
</span><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, b)) -&gt; StateL s b) -&gt; (s -&gt; (s, b)) -&gt; StateL s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514403"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514403"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-62"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514402"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514402"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514401"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514401"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a -&gt; b)
</span><a href="#local-6989586621679514406"><span class="hs-identifier hs-var">kf</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514403"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-63"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679514400"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514400"><span class="hs-identifier hs-var">s''</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514399"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514399"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514404"><span class="hs-identifier hs-var">kv</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514402"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-64"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514400"><span class="hs-identifier hs-var">s''</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514401"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514399"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span>    </span><span id="local-6989586621679514398"><span class="annot"><span class="annottext">liftA2 :: forall a b c.
(a -&gt; b -&gt; c) -&gt; StateL s a -&gt; StateL s b -&gt; StateL s c
</span><a href="GHC.Base.html#liftA2"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftA2</span></a></span></span><span> </span><span id="local-6989586621679514396"><span class="annot"><span class="annottext">a -&gt; b -&gt; c
</span><a href="#local-6989586621679514396"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span id="local-6989586621679514395"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514395"><span class="hs-identifier hs-var">kx</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-type">StateL</span></a></span><span> </span><span id="local-6989586621679514394"><span class="annot"><span class="annottext">s -&gt; (s, b)
</span><a href="#local-6989586621679514394"><span class="hs-identifier hs-var">ky</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, c)) -&gt; StateL s c
forall s a. (s -&gt; (s, a)) -&gt; StateL s a
</span><a href="Data.Functor.Utils.html#StateL"><span class="hs-identifier hs-var">StateL</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, c)) -&gt; StateL s c) -&gt; (s -&gt; (s, c)) -&gt; StateL s c
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679514393"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514393"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-66"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514392"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514392"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514391"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514391"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514395"><span class="hs-identifier hs-var">kx</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514393"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-67"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679514390"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514390"><span class="hs-identifier hs-var">s''</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514389"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679514389"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, b)
</span><a href="#local-6989586621679514394"><span class="hs-identifier hs-var">ky</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514392"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-68"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514390"><span class="hs-identifier hs-var">s''</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; c
</span><a href="#local-6989586621679514396"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514391"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679514389"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-comment">-- right-to-left state-transforming monad</span><span>
</span><span id="line-71"></span><span class="hs-keyword">newtype</span><span> </span><span id="StateR"><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span></span><span> </span><span id="local-6989586621679514532"><span class="annot"><a href="#local-6989586621679514532"><span class="hs-identifier hs-type">s</span></a></span></span><span> </span><span id="local-6989586621679514531"><span class="annot"><a href="#local-6989586621679514531"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="StateR"><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="runStateR"><span class="annot"><span class="annottext">forall s a. StateR s a -&gt; s -&gt; (s, a)
</span><a href="Data.Functor.Utils.html#runStateR"><span class="hs-identifier hs-var hs-var">runStateR</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679514532"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679514532"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679514531"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">-- | @since 4.0</span><span>
</span><span id="line-74"></span><span id="local-6989586621679514528"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514384"><span class="annot"><a href="GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514528"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-75"></span><span>    </span><span id="local-6989586621679514383"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; StateR s a -&gt; StateR s b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span id="local-6989586621679514382"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514382"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span id="local-6989586621679514381"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514381"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, b)) -&gt; StateR s b
forall s a. (s -&gt; (s, a)) -&gt; StateR s a
</span><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, b)) -&gt; StateR s b) -&gt; (s -&gt; (s, b)) -&gt; StateR s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514380"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514380"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514379"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514379"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514378"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514378"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514381"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514380"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514379"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514382"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514378"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-comment">-- | @since 4.0</span><span>
</span><span id="line-78"></span><span id="local-6989586621679514525"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679514369"><span id="local-6989586621679514371"><span class="annot"><a href="GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514525"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-79"></span><span>    </span><span id="local-6989586621679514368"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; StateR s a
</span><a href="GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679514367"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514367"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, a)) -&gt; StateR s a
forall s a. (s -&gt; (s, a)) -&gt; StateR s a
</span><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514366"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514366"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514366"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514367"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>    </span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span id="local-6989586621679514365"><span class="annot"><span class="annottext">s -&gt; (s, a -&gt; b)
</span><a href="#local-6989586621679514365"><span class="hs-identifier hs-var">kf</span></a></span></span><span> </span><span id="local-6989586621679514364"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. StateR s (a -&gt; b) -&gt; StateR s a -&gt; StateR s b
</span><a href="GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;*&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span id="local-6989586621679514363"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514363"><span class="hs-identifier hs-var">kv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, b)) -&gt; StateR s b
forall s a. (s -&gt; (s, a)) -&gt; StateR s a
</span><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, b)) -&gt; StateR s b) -&gt; (s -&gt; (s, b)) -&gt; StateR s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514362"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514362"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-81"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514361"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514361"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514360"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514360"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514363"><span class="hs-identifier hs-var">kv</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514362"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-82"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679514359"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514359"><span class="hs-identifier hs-var">s''</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514358"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514358"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a -&gt; b)
</span><a href="#local-6989586621679514365"><span class="hs-identifier hs-var">kf</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514361"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-83"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514359"><span class="hs-identifier hs-var">s''</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679514358"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514360"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-84"></span><span>    </span><span id="local-6989586621679514357"><span class="annot"><span class="annottext">liftA2 :: forall a b c.
(a -&gt; b -&gt; c) -&gt; StateR s a -&gt; StateR s b -&gt; StateR s c
</span><a href="#local-6989586621679514357"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftA2</span></a></span></span><span> </span><span id="local-6989586621679514356"><span class="annot"><span class="annottext">a -&gt; b -&gt; c
</span><a href="#local-6989586621679514356"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span id="local-6989586621679514355"><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514355"><span class="hs-identifier hs-var">kx</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-type">StateR</span></a></span><span> </span><span id="local-6989586621679514354"><span class="annot"><span class="annottext">s -&gt; (s, b)
</span><a href="#local-6989586621679514354"><span class="hs-identifier hs-var">ky</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, c)) -&gt; StateR s c
forall s a. (s -&gt; (s, a)) -&gt; StateR s a
</span><a href="Data.Functor.Utils.html#StateR"><span class="hs-identifier hs-var">StateR</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, c)) -&gt; StateR s c) -&gt; (s -&gt; (s, c)) -&gt; StateR s c
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679514353"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514353"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-85"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679514352"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514352"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514351"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679514351"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, b)
</span><a href="#local-6989586621679514354"><span class="hs-identifier hs-var">ky</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514353"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-86"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679514350"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514350"><span class="hs-identifier hs-var">s''</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679514349"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514349"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (s, a)
</span><a href="#local-6989586621679514355"><span class="hs-identifier hs-var">kx</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514352"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-87"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679514350"><span class="hs-identifier hs-var">s''</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; c
</span><a href="#local-6989586621679514356"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679514349"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679514351"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="hs-comment">-- See Note [Function coercion]</span><span>
</span><span id="line-90"></span><span id="local-6989586621679514516"><span id="local-6989586621679514517"><span id="local-6989586621679514518"><span class="annot"><a href="Data.Functor.Utils.html#%23."><span class="hs-operator hs-type">(#.)</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Coercible"><span class="hs-identifier hs-type">Coercible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514518"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679514517"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679514518"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679514517"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679514516"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679514518"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679514516"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679514517"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span></span></span></span><span>
</span><span id="line-91"></span><span id="%23."><span class="annot"><span class="annottext">#. :: forall b c a. Coercible b c =&gt; (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="Data.Functor.Utils.html#%23."><span class="hs-operator hs-var hs-var">(#.)</span></a></span></span><span> </span><span id="local-6989586621679514344"><span class="annot"><span class="annottext">b -&gt; c
</span><a href="#local-6989586621679514344"><span class="hs-identifier hs-var">_f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; a -&gt; c
</span><a href="../../ghc-prim/src/GHC.Prim.html#coerce"><span class="hs-identifier hs-var">coerce</span></a></span><span>
</span><span id="line-92"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">#.</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span class="hs-comment">{-
Note [Function coercion]
~~~~~~~~~~~~~~~~~~~~~~~

Several functions here use (#.) instead of (.) to avoid potential efficiency
problems relating to #7542. The problem, in a nutshell:

If N is a newtype constructor, then N x will always have the same
representation as x (something similar applies for a newtype deconstructor).
However, if f is a function,

N . f = \x -&gt; N (f x)

This looks almost the same as f, but the eta expansion lifts it--the lhs could
be _|_, but the rhs never is. This can lead to very inefficient code.  Thus we
steal a technique from Shachaf and Edward Kmett and adapt it to the current
(rather clean) setting. Instead of using  N . f,  we use  N #. f, which is
just

coerce f `asTypeOf` (N . f)

That is, we just *pretend* that f has the right type, and thanks to the safety
of coerce, the type checker guarantees that nothing really goes wrong. We still
have to be a bit careful, though: remember that #. completely ignores the
*value* of its left operand.
-}</span><span>
</span><span id="line-120"></span></pre></body></html>